import {
	defineConfig,
	loadEnv
} from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import './common/router/createRouterFile.js'; //自动生成router文件
export default defineConfig(({
	command,
	mode
}) => {
	// console.log('.env ', `.env.${mode}`, `${command}环境`)
	let env = loadEnv(mode, __dirname, 'VITE_');
	return {
		build: {
			// rollupOptions: {
			// 	external: ['axios'],
			// },
			sourcemap: true,
		},
		// transpileDependencies: ['uview-ui','js-md5'],
		plugins: [
			uni(),
		],
		define: {
			// 自定义配置环境变量
			'VITE_ENV': env
		},
		server: {
			host: true,
			port: 3002,
			hmr: {
				overlay: true,
			},
			proxy: {
				'/dev_api': {
					target: 'http://172.16.3.245:1001/', //目标源，目标服务器，真实请求地址
					changeOrigin: true, //支持跨域
					rewrite: (path) => path.replace(/^\/dev_api/, ""), //重写真实路径,替换/dev_api
				}
			}
		},
	};
})